import 'package:dsbridge_flutter/dsbridge_flutter.dart';

typedef JsBridgeOpenURL = void Function(String url,
    {String? title, String? query});
typedef JsBridgeBackURL = void Function({
  bool? main,
  String? url,
});

class JsBridge extends JavaScriptNamespaceInterface {
  final JsBridgeOpenURL openURL;
  final JsBridgeBackURL backURL;
  JsBridge({
    required this.openURL,
    required this.backURL,
  });
  @override
  void register() {
    registerFunction(newPage, functionName: "newPage");
    registerFunction(backPage, functionName: "backPage");
  }

  String newPage(Map<String, dynamic> param) {
    String url = param['page'];
    String? query = param['param'];
    openURL(url, query: query);
    return '';
  }

  String backPage(Map<String, dynamic> param) {
    backURL();
    return '';
  }
}
